package com.shops.servlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.util.Enumeration;
import java.util.Properties;

/**
 * @author gexiang
 * @Description:
 * @date 2020/7/1811:04
 */
public class FirstServlet extends HttpServlet {
    private static final Logger log = LoggerFactory.getLogger(HttpServlet.class);
    int count = 0;

    public FirstServlet() {
        System.out.println("构造方法");
    }

    @Override
    public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        PrintWriter writer = res.getWriter();
        count++;
        System.out.println("我在fs中,这是请求我的第"+count+"次");
        writer.println(count);
        ServletContext servletContext = req.getSession(true).getServletContext();
        InputStream resourceAsStream = servletContext.getResourceAsStream("C:\\Users\\EDZ\\Desktop\\db.properties");
        Properties properties = new Properties();
        properties.load(resourceAsStream);
        System.out.println(properties.getProperty("jdbc.url"));
    }

    @Override
    public void destroy() {
        System.out.println("开始销毁");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("开始初始化servelt");
        String servletName = super.getServletName();
        System.out.println("servletName = " + servletName);
    }


}
